package com.rmondjone.face.adapter

import android.graphics.Color
import android.text.TextUtils
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.rmondjone.androidcamerademo.R
import com.rmondjone.androidcamerademo.bean.ListBean
import com.rmondjone.androidcamerademo.bean.Result

/**
 * copyright：
 * @author：anthui creation date： .
 * @since: 1.0.0
 * @describe:
 */
class SymptomAdapter : BaseQuickAdapter<Result, BaseViewHolder>(R.layout.item_zhengzhuang) {
    override fun convert(helper: BaseViewHolder, item: Result) {

        helper.setText(R.id.tv_title, item.name)

        setContent(helper, item.list.firstOrNull())

        helper.setGone(R.id.view_line, helper.adapterPosition != 0)

//        helper.setText(R.id.tv_content, item.list.firstOrNull()?.info ?: "")

        helper.getView<RecyclerView>(R.id.rv_type).apply {
            val itemCheckAdapter = ItemCheckAdapter(item.list)

            layoutManager = GridLayoutManager(context, 4)
            adapter = itemCheckAdapter

            itemCheckAdapter.setOnItemClickListener { adapter, view, position ->

                setContent(helper, itemCheckAdapter.getItem(position))
                itemCheckAdapter.checkPosition = position
                adapter.notifyDataSetChanged()

            }

        }


    }


    private fun setContent(helper: BaseViewHolder, listBean: ListBean?) {

        var view = helper.getView<TextView>(R.id.tv_content)
        if (listBean == null || TextUtils.isEmpty(listBean.info)) {
            view.visibility = View.GONE
            return
        }
        view.visibility = View.VISIBLE
        SpanUtils.with(helper.getView(R.id.tv_content)).append(listBean.name + ":").setForegroundColor(Color.parseColor("#BE9B6D")).append(listBean.info).create()


    }
}